import pandas as pd
import numpy as np

np.random.seed(0)

dates = pd.date_range("20210101", periods=6)
df = pd.DataFrame(np.random.randn(6, 5), index=dates, columns=["a", "b", "c", "d", "e"])

# 设置nan的值
df.iloc[0, 1] = np.nan
df.iloc[1, 2] = np.nan
print(df)

# 丢弃行或列，由axis指定， how=any表示只要由nan的值就丢弃
res = df.dropna(axis=0, how="any")
print(res)

# 丢弃行或列，由axis指定， how=all表示该行或该列都为nan时才丢弃
res = df.dropna(axis=0, how="all")
print(res)

# 填充为空的值
res = df.fillna(value=0)
print(res)

# 判断是否至少有一个是True
res = np.any(df.isnull() == True)
print(res)
